import { HttpClient, HttpParams } from '@angular/common/http';
import { inject, Injectable } from '@angular/core';
import { environment } from '../../../../environments/environment';
import { PagerResponse, UnifyResponse } from '../../../../common/response';
import { PostDto, PostQuery } from './types';


const baseUrl = environment.baseApiUrl


@Injectable({
  providedIn: 'root'
})
export class PostService {

  private readonly http = inject(HttpClient)


  constructor() { }

  getPostList(params: PostQuery) {
    const httpParams = new HttpParams()
      .set('postCode', params.postCode || '')
      .set('postName', params.postName || '')
      .set('status', params.status || '')
    return this.http.get<PagerResponse<any>>(`${baseUrl}/system/post/list`, {
      params: httpParams
    }) 
  }

  exportPostList(data: PostDto)  {
    return this.http.post<UnifyResponse<any>>(`${baseUrl}/system/post/export`, data) 
  }

  addPost(data: PostDto)  {
    return this.http.post<UnifyResponse<any>>(`${baseUrl}/system/post`, data) 
  }

  updatePost(data: PostDto)  {
    return this.http.post<UnifyResponse<any>>(`${baseUrl}/system/post`, data)  
  }


  delPost(id: number)  {
    return this.http.delete<UnifyResponse<any>>(`${baseUrl}/system/post/${id}`) 
  }

  postOptionSelect() {
    return this.http.get<UnifyResponse<any>>(`${baseUrl}/system/post/optionselect`)
  }

}
